<?php
class EventRef extends Zend_Db_Table_Abstract
{
    protected $_name = 'event_ref';

    public function add($userId, $eventId)
    {
        $data = array('eventId'=> $eventId, 'userId'=>$userId);
        $this->insert($data);
    }

    public function del($userId, $eventId)
    {
        $db = &$this->getAdapter();
        $where = $db->quoteInto('eventId=?', $eventId).$db->quoteInto(' and userId=?', $userId);
        return $this->delete($where);
    }

    public function findByUser($userId)
    {
        $db = &$this->getAdapter();

        $sql = $db->quoteInto('select * from '.$this->_name.' where userId=?', $userId);
        $result = $db->query($sql);
        $res = $result->fetchAll();
        var_dump($res);
        exit;
    }

    public function findByEvent($eventId)
    {
        $db = &$this->getAdapter();

        $sql = $db->quoteInto('select * from '.$this->_name.' where eventId=?', $eventId);
        $result = $db->query($sql);
        $res = $result->fetchAll();
        var_dump($res);
        exit;
    }
}
